package rush.rushcampus.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import rush.rushcampus.common.Result;
import rush.rushcampus.dto.FoundPublicationDto;
import rush.rushcampus.dto.FoundPageDto;
import rush.rushcampus.service.IFoundService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rush
 * @since 2024-06-14
 */
@RestController
@RequestMapping("/found")
@Api(tags = "失物招领")
public class FoundController {
    @Autowired
    private IFoundService foundService;
    //分页查找所有失物招领信息
    @Transactional
    //发布失物招领信息
    @ApiOperation(value = "发布失物招领信息")
    @PutMapping("/add")
    public Result addFound(@RequestBody FoundPublicationDto foundPublicationDto){

        foundService.addFound(foundPublicationDto);
        return Result.success("发布成功");
    }
    //分页查询失物招领信息
    @ApiOperation(value = "分页查询失物招领信息(如果查询全部标签，FoundTagId传参为0)")
    @PostMapping("/list")
    public Result list(@RequestBody FoundPageDto foundPageDto){
        return Result.success(foundService.listFound(foundPageDto));
    }
    @ApiOperation(value = "删除失物招领信息")
    @DeleteMapping("/remove")
    public Result remove(Long id , Integer commentType){
        foundService.removeFound(id , commentType);
        return Result.success("删除成功");
    }
    @ApiOperation(value = "根据id查询失物招领")
    @GetMapping("/getFoundById")
    public Result getFoundById(Long id){
        return Result.success(foundService.getFoundById(id));
    }

}
